{% extends base %}

{% block head %}

<style type="text/css">
    .td-no {
        width: 50px;
    }

    .label {
        width: 150px;
        text-align: right;
        display: table-cell;
    }

    .dialog-wrap {
        padding: 10px;
    }

    .list-heading {
        line-height: 32px;
    }

</style>

{% end %}

{% block body_left %}

<div class="card">
    <h3 class="card-title btn-line-height">
        <span>用户管理</span>

        <div class="float-right">
            <a class="btn add-user-btn">新增</a>
            <button class="btn-default" onclick="javascript:history.back()">返回</button>
        </div>
    </h3>
</div>

<div class="card">

    <table class="table col-md-12">
        <tr>
            <th class="index-td">编号</th>
            <th>登录名</th>
            <th>上次登录</th>
            <th>操作</th>
        </tr>
        {% for user_info in user_list %}
        <tr>
            <td class="index-td">{{user_info.id}}</td>
            <td><a class="link edit-btn" href="{{_server_home}}/system/user?name={{user_info.name}}">{{user_info.name}}</a></td>
            <td>{{user_info.login_time}}</td>
            <td>
                {% if user_info.name != "admin" %}
                    {% if user_info.status == 0 %}
                    <a data-name="{{user_info.name}}" data-id="{{user_info.id}}" 
                        onclick="xnoteDeleteUser(this)"
                        class="btn danger delete-user-btn">删除</a>
                    {% end %}

                    {% if user_info.status == -1 %}
                        <span class="red">已删除</span>
                    {% end %}
                {% end %}
            </td>
        </tr>
        {% end %}
    </table>
</div>

<div id="dialogContent" class="col-md-12 hide">
    <div class="dialog-wrap">
        <form class="dialog-form">
            <table class="no-border-table col-md-12">
                <tr>
                    <td class="label">用户名</td>
                    <td><input name="name" value=""></td>
                </tr>
                <tr>
                    <td class="label">密码</td>
                    <td><input name="password" value=""></td>
                </tr>
                <tr>
                    <td class="label">salt</td>
                    <td class="salt"></td>
                </tr>
                <tr>
                    <td class="label">token</td>
                    <td class="token"></td>
                </tr>
                <tr>
                    <td class="label">上次更新</td>
                    <td class="mtime"></td>
                </tr>
                <tr>
                    <td class="label">上次登录</td>
                    <td class="login_time"></td>
                </tr>
            </table>
        </form>
    </div>
</div>

{% include user/component/user_script.html %}

<div class="card">
    {% include common/pagination.html %}
</div>

<script type="text/javascript">
$(function () {

    $(".add-user-btn").click(function (e) {
        xnote.prompt("新增用户", "", function (name) {
            $.post("/user/add", {name: name}, function (resp) {
                if (resp.code == "success") {
                    window.location = "/system/user?name=" + name;
                } else {
                    xnote.alert("新增用户失败:" + resp.message);
                }
            });
        });
    });
})
</script>

{% end %}

{% block body_right %}
    {% include system/component/admin_nav.html %}
{% end %}